package com.wzdigit.wms.wms.controller.inv.count;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.util.HttpSessionUtil;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.domain.dto.inv.count.*;
import com.wzdigit.wms.wms.service.inv.count.StockCountDtlGoodsService;
import com.wzdigit.wms.wms.service.inv.count.StockCountDtlService;
import com.wzdigit.wms.wms.service.inv.count.StockCountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;

@RestController
@Api(tags = "盘点任务明细PDA")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class StockCountDtlGoodsController {

    public static final String REQUEST_MODEL = "/stockCountDtlGoods";

    @Autowired
    StockCountDtlGoodsService stockCountDtlGoodsService;

    @ApiOperation(value = "按物料-扫码盘点校验",notes = "按物料-扫码盘点校验SN")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/matnr/scanSn/{sn}/{skuCode}/{isFirst}/{headerId}")
    public Result<InvCountDtlResponse> scanMatnrSn(@PathVariable("sn") String sn ,
                                                   @PathVariable("isFirst")Boolean isFirst,
                                                   @PathVariable("skuCode") String skuCode,
                                                   @PathVariable("headerId")BigDecimal headerId, HttpServletRequest request,HttpServletResponse servletResponse){
        try {
            String loginName = HttpSessionUtil.getLoginName(request);
            return stockCountDtlGoodsService.saveMatnrScan(sn,skuCode,isFirst,headerId,loginName);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }


    @ApiOperation(value = "按库位-扫码盘点校验",notes = "按库位-扫码盘点校验SN")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/stock/scanSn/{sn}/{locCode}/{isFirst}/{headerId}")
    public Result<InvCountDtlResponse> scanLocSn(@PathVariable("sn") String sn ,
                                                 @PathVariable("locCode") String locCode,
                                                 @PathVariable("headerId") BigDecimal headerId,
                                                 @PathVariable("isFirst") Boolean isFirst, HttpServletRequest request,HttpServletResponse servletResponse){
        try {
            String loginName = HttpSessionUtil.getLoginName(request);
            return stockCountDtlGoodsService.saveStockScan(sn,locCode,isFirst,headerId,loginName);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }


    @ApiOperation(value = "调整实盘数量",notes = "调整实盘数量")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/matnr/changeQty/{sn}/{qty}/{headerId}")
    public Result selectDetailAll(@PathVariable("sn") String sn , @PathVariable("qty") BigDecimal qty,
                                  @PathVariable("headerId") BigDecimal headerId,
                                  HttpServletResponse servletResponse, HttpServletRequest request){
        try {
            String loginName = HttpSessionUtil.getLoginName(request);
            return stockCountDtlGoodsService.changeQty(sn,qty,headerId,loginName);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }



    @ApiOperation(value = "序号明细",notes = "序号明细")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/list/{dtlId}")
    public  List<InvCountDtlGoodsResponse> selectDetailAll(@PathVariable("dtlId") BigDecimal dtlId, HttpServletResponse servletResponse, HttpServletRequest request){
        try {
            String loginName = HttpSessionUtil.getLoginName(request);
            return stockCountDtlGoodsService.list(dtlId);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }













}
